import React, { Component } from 'react';
import { withRouter, Route } from 'react-router-dom';
export default withRouter(class Mynav extends Component {
    render() {
        // 获取标题
        const text = this.props.children
        // 获取跳转的链接
        const url = this.props.to
        // console.log(url);
        // 获取要显示成什么标签
        const Tag = this.props.tag || 'a'
        // console.log('Tag', Tag);
        // 定义组件的行内样式style
        let style = { cursor: 'pointer' }
        return (
            <Route path={url} children={(props) => {
                // console.log('props', props)
                if (props.match) {
                    // 表示当前路径url匹配
                    // console.log('url', url)
                    style.background = 'red'
                }
                // console.log('url', url)
                return <Tag style={style} onClick={() => this.goFn(props, url)}>{text}</Tag>
            }}></Route>

        )
    }

    goFn(props, url) {
        // console.log('goFn', this);
        // console.log(url);
        //this.props.history.push(url)
        // console.log(props.history.push, url);
        //console.log(props);
        props.history.push(url)
    }
})
